package com.tan.websocket.handler;

import com.tan.common.domain.chat.ChatInfo;
import com.tan.common.dto.chat.ChatInfoDTO;
import com.tan.core.utils.ThreadPoolTool;
import com.tan.websocket.service.IChatInfoService;
import jakarta.annotation.Resource;

/**
 * @author Tan-Bowen
 * @description
 * @date 2025/1/28 22:34
 */
public abstract class MainFrameAbstractService implements MainFrameService {

    @Resource
    private IChatInfoService chatInfoService;

    @Resource
    private ThreadPoolTool threadPool;


    public void createChatInfo(ChatInfoDTO chatInfoDTO) {
        // 信息存储
        ChatInfo info = new ChatInfo();
        info.setTextContent(chatInfoDTO.getTextContent());
        info.setSender(chatInfoDTO.getSender());
        info.setReceiver(chatInfoDTO.getReceiver());
        info.setMessageType(chatInfoDTO.getMessageType());
        // 异步线程插入数据 后期修改成mq
        threadPool.execute(() -> {
            chatInfoService.createChatInfo(info);
        });
    }
}
